package cn.outmaneuver.outman.demo.web.controller;
/**
 * Copyright 2023-2023 by DongYaoMing. All Rights Reserved.
 */

import cn.outmaneuver.outman.demo.web.domain.request.ComplexObjectDTO;
import cn.outmaneuver.outman.demo.web.domain.request.GetAndQueryDTO;
import cn.outmaneuver.outman.demo.web.domain.request.PostAndFormDTO;
import com.alibaba.fastjson2.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * RequestDemoController
 * <p> 基础请求demo示例 </p>
 *
 * @author DongYaoMing
 * @version 1.0
 * @date 2023/09/24
 */
@RestController
@RequestMapping("/demo/request")
public class RequestDemoController {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    @GetMapping("/getAndQuery")
    public String getAndQuery(String method, @Validated GetAndQueryDTO queryDTO) {
        log.info("接收到的参数：[method={},queryDTO={}]", method, JSON.toJSONString(queryDTO));
        return "success";
    }

    @PostMapping("/postAndFormData")
    public String postAndFormData(String method, @Validated PostAndFormDTO paramDTO) {
        log.info("接收到的参数：[method={},paramDTO={}]", method, JSON.toJSONString(paramDTO));
        return "success";
    }

    @PostMapping("/postAndFormUrlEncoded")
    public String postAndFormUrlEncoded(String method, @Validated PostAndFormDTO paramDTO) {
        log.info("接收到的参数：[method={},paramDTO={}]", method, JSON.toJSONString(paramDTO));
        return "success";
    }

    @PostMapping("/postAndRawText")
    public String postAndRawText(String method, @RequestBody String paramData) {
        log.info("接收到的参数：[method={},paramDTO={}]", method, paramData);
        return "success";
    }

    @PostMapping("/postAndRawJson")
    public String postAndRawJson(String method, @RequestBody @Validated PostAndFormDTO paramDTO) {
        log.info("接收到的参数：[method={},paramDTO={}]", method, JSON.toJSONString(paramDTO));
        return "success";
    }

    @PostMapping("/postAndRawComplexJson")
    public String postAndRawComplexJson(String method, @RequestBody @Validated ComplexObjectDTO paramDTO) {
        log.info("接收到的参数：[method={},paramDTO={}]", method, JSON.toJSONString(paramDTO));
        return "success";
    }

    @PostMapping("/postAndRawComplexJson2")
    @Validated
    public String postAndRawComplexJson2(String method, @RequestBody @Valid ComplexObjectDTO paramDTO) {
        log.info("接收到的参数：[method={},paramDTO={}]", method, JSON.toJSONString(paramDTO));
        return "success";
    }
}
